package exercise;

public class LC48 {
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        int[][] matrixCopy = new int[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                matrixCopy[i][j] = matrix[i][j];
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int x = j, y = n - i - 1;
                matrix[x][y] = matrixCopy[i][j];
            }
        }
    }
}

// 0, 0 -> 0, 2   0, 0 -> 0, 3
// 0, 2 -> 2, 2   0, 2 -> 2, 3
// 0, 1 -> 1, 2   0, 1 -> 1, 3
// 1, 0 -> 0, 1   0, 3 -> 3, 3
// 1, 1 -> 1, 1   1, 0 -> 0, 2
// 1, 2 -> 2, 1   1, 1 -> 1, 2
// 2, 0 -> 0, 0   1, 2 -> 2, 2
// 2, 1 -> 1, 0   1, 3 -> 3, 2
// 2, 2 -> 2, 0   2, 0 -> 0, 1
//                2, 1 -> 1, 1
//                2, 2 -> 2, 1
//                2, 3 -> 3, 1
//                3, 0 -> 0, 0
